// pages/consult/djzx/components/dianjizixunbiaoqian.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
// 接收外部传入的标签数据
customTags: {
  type: Array,
  value: []
}
  },

  /**
   * 组件的初始数据
   */
  data: {
    tags: [],
    maxSelect: 3,
    selectedCount: 0
  },
  attached: function () {
    // 组件挂载时，将外部传入的标签数据赋值给内部的tags
    this.setData({
      tags: this.properties.customTags
    });
  },
  methods: {
    selectTag: function (e) {
      const index = e.currentTarget.dataset.index;
      const { tags, selectedCount, maxSelect } = this.data;
      const tag = tags[index];

      if (tag.selected) {
        tag.selected = false;
        this.setData({
          ['tags[' + index + '].selected']: false,
          selectedCount: selectedCount - 1
        });
      } else {
        if (selectedCount < maxSelect) {
          tag.selected = true;
          this.setData({
            ['tags[' + index + '].selected']: true,
            selectedCount: selectedCount + 1
          });
        } else {
          wx.showToast({
            title: '最多只能选3个标签',
            icon: 'none'
          });
        }
      }
    }
  }
  /**
   * 组件的方法列表
   */

})
